﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands.二级科室;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.二级科室
{
    public class AddDeptSubCategoryCommandHandler : IRequestHandler<AddDeptSubCategoryCommand, APIResult<int>>
    {
        private readonly IBaseRespository<DeptSubCategoryModel> depRep;

        public AddDeptSubCategoryCommandHandler(IBaseRespository<DeptSubCategoryModel> depRep)
        {
            this.depRep = depRep;
        }

        public async Task<APIResult<int>> Handle(AddDeptSubCategoryCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();
            DeptSubCategoryModel dep = new DeptSubCategoryModel();
            dep.DepartmentId = request.DepartmentId;
            dep.Name = request.Name;
            dep.Intro = request.Intro;
            dep.Css = 2;
            dep.Status = request.Status;
            dep.CreateTime = DateTime.Now;
            dep.IsDeleted = false;
            dep.CreateName = request.CreateName;
            await depRep.AddAsync(dep);


            return await Task.FromResult(result);
        }
    }
}
